package com.erp.module.pieceworkGrouping.PieceworkGroupingXz

import android.app.Activity
import android.content.Intent
import android.util.Log
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.erp.R
import com.erp.activity.BaseActivity
import com.erp.bean.PieceworkGroupingNameBean
import com.erp.module.pieceworkGrouping.PieceworkGroupingContract
import com.erp.myAdapter.ArrayAdapter
import com.erp.myAdapter.PieceworkGroupingAdater
import com.erp.util.Myutil
import com.taobao.accs.ACCSManager.mContext
import kotlinx.android.synthetic.main.activity_piecework_grouping_xx.*
import kotlinx.android.synthetic.main.header_knoya.iv_header_left
import kotlinx.android.synthetic.main.header_knoya.tv_header_title


class PieceworkGroupingXzAcitivity : BaseActivity(), View.OnClickListener, PieceworkGroupingContract.ProductionGroupingView {
    lateinit var adapter : PieceworkGroupingAdater

    lateinit var PGlist : MutableList<PieceworkGroupingNameBean>

    var Ids: ArrayList<String> = ArrayList<String>()
    var Names: ArrayList<String> = ArrayList<String>()

    lateinit var updialog : AlertDialog

    lateinit var KP : PieceworkGroupingXzAcitivityP
    override fun getLayoutId(): Int {
        return R.layout.activity_piecework_grouping_xx
    }

    override fun initCreate() {
        iv_header_left.visibility = View.VISIBLE
        tv_header_title.text = "选择分组"
        iv_header_left.setOnClickListener(this)
        BtGuolv.setOnClickListener(this)
        PGlist = ArrayList()
        val layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        adapter = PieceworkGroupingAdater(this, PGlist)
        LvFenzuData.layoutManager = layoutManager
        LvFenzuData.addItemDecoration(DividerItemDecoration(this, LinearLayoutManager.VERTICAL))
        LvFenzuData.adapter = adapter
        KP = PieceworkGroupingXzAcitivityP(this, this,PGlist)
        KP.getGroupingNames()
        AtHGangweiName.setOnClickListener(this)
        updialog = Myutil.showupdatedialog(this@PieceworkGroupingXzAcitivity, "正在搜索", false)
        KP.getGroupingList("","","")
    }

    override fun onClick(v: View?) {
        when(v){
            BtGuolv -> {
                updialog = Myutil.showupdatedialog(this@PieceworkGroupingXzAcitivity, "正在搜索", false)
                KP.getGroupingList(AtHGangweiName.text.toString(),EtName.text.toString(),EtStaffName.text.toString())
            }
            AtHGangweiName -> {
                AtHGangweiName.showDropDown()
            }
            iv_header_left -> {
                finish()
            }
        }
    }

    override fun clickGouping(bean: PieceworkGroupingNameBean) {
        editor.putString("gangwei_grouping_id",bean.kgg_id).commit()
        var intent = Intent()
        setResult(Activity.RESULT_OK, intent)
        finish()
    }

    override fun getGroupingNamesOk(ids: ArrayList<String>, names: ArrayList<String>) {
        this.Ids = ids
        this.Names = names
        val av = ArrayAdapter(this@PieceworkGroupingXzAcitivity, android.R.layout.simple_dropdown_item_1line, Names)
        AtHGangweiName.setAdapter(av)
    }

    override fun getGroupingNamesNo() {
    }

    override fun getGroupingListOk() {
        updialog.dismiss()
        adapter.notifyDataSetChanged()
    }

    override fun getGroupingListNo() {
        updialog.dismiss()
    }
}